package com.ruoyi.xiaoshou.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.xiaoshou.domain.SaleRequest;
import com.ruoyi.xiaoshou.domain.SaleRequestDetail;
import com.ruoyi.xiaoshou.dto.AddDetail;
import com.ruoyi.xiaoshou.dto.AddDto;
import com.ruoyi.xiaoshou.service.ISaleRequestService;
import com.ruoyi.xiaoshou.service.SaleRequestDetailService;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/saleRequestDetail")
public class SaleRequestDetailController {

    @Autowired
    private SaleRequestDetailService saleRequestDetailService;

    Logger logger = LoggerFactory.getLogger(SaleRequestDetailController.class);
    /**
     * 查询销售申请列表
     */
    @RequiresPermissions("xiaoshou:detail:saleRequesList")
    @GetMapping(value = "/{orderId}")
    public AjaxResult list(@PathVariable("orderId") int orderId) {
        return saleRequestDetailService.getList(orderId);
    }

    /**
     * 查询销售申请列表
     */
    @RequiresPermissions("xiaoshou:detail:addDto")
    @GetMapping(value = "addDto")
    public AjaxResult addDto(AddDto addDto) {
        logger.info("SaleRequestDetailController addDetail start....addDto:"+addDto);
        return saleRequestDetailService.addDetail(addDto);
    }

    @RequiresPermissions("xiaoshou:detail:updDetail")
    @PostMapping(value = "updDetail")
    public AjaxResult updDetail(@RequestBody List<SaleRequestDetail> saleRequestDetail) {
        logger.info("SaleRequestDetailController updDetail start....saleRequestDetail:"+saleRequestDetail.toString());
        return saleRequestDetailService.addOrderDetail(saleRequestDetail);
    }

}
